<?php

namespace app\controller;


use think\facade\Request;

class User
{
    public function login()
    {
        $param = Request::post();
        foreach ($param as $key => &$item) {
            if ($key == 'password') {
                $item = md5($item);
            }
            $item = trim($item);
        }
        $userModel = new \app\model\User();
        $data=$userModel->getOneData($param);
        if ($data) $meta=['msg'=>'登录成功','status'=>200];
        else $meta=['msg'=>'登录失败','status'=>400];
        return json(['data'=>$data,'meta'=>$meta]);
    }

    public function changePass()
    {
        $param = Request::post();
        $userModel = new \app\model\User();
        $data=$userModel->find($param['id']);
        if ($data&&$data->password==md5($param['oldPass'])) {
            $data->password = md5($param['pass']);
            $data->save();
            $meta = ['msg' => '修改密码成功', 'status' => 200];
        }else $meta=['msg'=>'原密码错误','status'=>400];
        return json(['meta'=>$meta]);
    }
}